<?
/* Copyright (c) 2008-2011 Submit Consulting. Lima-Peru. All Right Reserved.
 * @author Ing. Angel Sullon M. (asullom@hotmail.com)
 * Created: 21.SEP.2000
 * Last Modify: 11.AGO.2011
 * Description of PrepareQuery: Permite el compilado de una consulta SQL
 */
class PrepareQuery {
	var $qry;
	var $params = array();
	var $i = 0;

	function __construct($qry){
		$this->qry = $qry;
	}

	public function set($value){
		//$value = mysql_escape_string($value);
                //$this->i=$this->i+1;
                if(!empty ( $value ))
                    $this->params[$this->i++] = "'".$value."'";
                else
                    $this->params[$this->i++] = "NULL";
                    
	}

	public function getQuery(){
                $query = '';
		$p = explode("?", $this->qry);
                if ( count($p)-1 > count($this->params) )
                        die("<p class=error>Value no found</p>");
                else  if ( count($p)-1 < count($this->params) )
                        die("<p class=error>Indice no found</p>");
		
		for($i=0; $i< count($this->params); $i++){
                    $query .= $p[$i].$this->params[$i];
		}
                $query .= $p[$i];
                //preg_replace("%\?%", "'$this->params[$i]'", $this->txt);
		return $query;
	}
}
?>
